Completed
Push — master ( 111ea3...33738e )
by Ajeh
31s
created

main.spec.js ➔ describe(ꞌUtility Helpersꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 50
rs 9.3333
nop 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A main.spec.js ➔ ... ➔ describe(ꞌ#cloneObjꞌ) 0 16 1
A main.spec.js ➔ ... ➔ describe(ꞌ#firstIndexꞌ) 0 20 1
A main.spec.js ➔ ... ➔ describe(ꞌ#mergeObjsꞌ) 0 10 1
1
/**
2
 * Created by Emmy on 10/7/2017.
3
 */
4
5
import * as Utility from '../../src/plugin/js/utilities'
6
import should from 'should'
7
8
describe('Utility Helpers', function () {
9
    describe('#cloneObj', function () {
10
11
        it('The problem: Altering an object "objA" affects "objB"', function () {
12
            let objA = {foo: 'abc', bar: '123'};
13
            let objB = objA;
14
            objA.bar = '1234';
15
            should(objA).be.exactly(objB)
16
        })
17
18
        it('The solution: cloned object should not be equal to original after altering', function () {
19
            let objA = {foo: 'abc', bar: '123'};
20
            let objB = Utility.cloneObj(objA);
21
            objA.bar = '1234';
22
            should(objA).not.be.exactly(objB)
23
        })
24
    })
25
26
    describe('#mergeObjs', function () {
27
28
        it('"objC" should be "objA" and "objB"', function () {
29
            let objA = {foo: 'abc'};
30
            let objB = {bar: '123'};
31
            let objC = Utility.mergeObjs(objA, objB);
32
33
            should(objC).have.keys('foo', 'bar')
34
        })
35
    })
36
37
    describe('#firstIndex', function () {
38
39
        let arr = [{color: 'yellow'}, {color: 'red'}, {color: 'blue'}]
40
41
        it('First index of red should be 1', function () {
42
            should(Utility.firstIndex(arr, 'red', 'color')).be.exactly(1).and.a.Number()
43
        })
44
45
        it('First index of yellow should be 0', function () {
46
            should(Utility.firstIndex(arr, 'yellow', 'color')).be.exactly(0).and.a.Number()
47
        })
48
49
        it('First index of blue should be 0', function () {
50
            should(Utility.firstIndex(arr, 'blue', 'color')).be.exactly(2).and.a.Number()
51
        })
52
53
        it('First index of black should be undefined', function () {
54
            should(Utility.firstIndex(arr, 'black', 'color')).be.exactly(-1).and.a.Number()
55
        })
56
    })
57
})